package com.xin.ruanjian.omsystem.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.xin.ruanjian.omsystem.activity.MainActivity;
import com.xin.ruanjian.omsystem.bean.IndexBean;
import com.xin.ruanjian.omsystem.fragment.CategoryFragment;
import com.xin.ruanjian.omsystem.fragment.CommentsFragment;
import com.xin.ruanjian.omsystem.fragment.GoodsFragment;
import com.xin.ruanjian.omsystem.fragment.MainFragment;
import com.xin.ruanjian.omsystem.fragment.OrderFragment;
import com.xin.ruanjian.omsystem.fragment.PersonFragment;
import com.xin.ruanjian.omsystem.fragment.ShopInfoFragment;
import com.xin.ruanjian.omsystem.utils.AnimationUtil;

import java.util.List;

/**
 * Created by local123 on 2018/2/2.
 */

public class ShopDetailVpAdapter extends FragmentPagerAdapter{
    public GoodsFragment goodsFragment;
    private CommentsFragment commentsFragment;
    private ShopInfoFragment shopInfoFragment;
    private Context context;
    private List<String> mTitles;
    private IndexBean.MsgBean.ShopBean mShopBean;

    public ShopDetailVpAdapter(Context context, FragmentManager fm, List<String> titles, IndexBean.MsgBean.ShopBean shopBean) {
        super(fm);
        this.context = context;
        mTitles = titles;
        mShopBean = shopBean;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            if (goodsFragment == null) { goodsFragment = GoodsFragment.newInstance(mShopBean.getShopid()+""); }
            return goodsFragment;
        }else if (position == 1) {
            if (commentsFragment == null) { commentsFragment = CommentsFragment.newInstance(); }
            return commentsFragment;
        }
        else {
            if (shopInfoFragment == null) { shopInfoFragment = ShopInfoFragment.newInstance(mShopBean); }
            return shopInfoFragment;
        }
    }

    @Override
    public int getCount() {
        return 3;
    }

    //此方法用来显示tab上的名字
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles.get(position % mTitles.size());
    }
}
